package com.bigflexlib.ds.container.utils
{
	import com.bigflexlib.ds.container.bag.IRWBag;
	import com.bigflexlib.ds.container.bag.impl.owBag;
	import com.bigflexlib.ds.container.zet.IOWSet;
	import com.bigflexlib.ds.container.zet.IRSet;
	import com.bigflexlib.ds.container.zet.impl.owSet;
	import com.bigflexlib.utils.BasicTestBase;

	public class ContainerUtilTest extends BasicTestBase
	{






		public function test_eq( ):void
		{
		
			assertTrue( ContainerUtil.eq( [ ], [ ] ) );
			assertTrue( ContainerUtil.eq( [ 1 ], [ 1 ] ) );
			assertTrue( ContainerUtil.eq( [ "a", "b" ], [ "b" , "a" ] ) );
			
			
			assertTrue( ContainerUtil.eq( owSet( ) , [ ] ) );
			assertTrue( ContainerUtil.eq( owSet( [ "a" ] ) , [ "a" ] ) );
			assertTrue( ContainerUtil.eq( owSet( [ "b", "a" ] ) , owBag( [ "a", "b" ] ) ) );


		
			assertFalse( ContainerUtil.eq( [ ], [ 9 ] ) );
			assertFalse( ContainerUtil.eq( [ 1 ], [  ] ) );
			assertFalse( ContainerUtil.eq( [ "a", "b" ], [ "b" , "a", "b" ] ) );
			
			
			assertFalse( ContainerUtil.eq( owSet( ) , [ "x" ] ) );
			assertFalse( ContainerUtil.eq( owSet( [ "a" ] ) , [ "a", "a" ] ) );
			assertFalse( ContainerUtil.eq( owSet( [ "b", "a" ] ) , owBag( [ "a" ] ) ) );
		
		
		}



		public function test_toArray( ):void
		{
			
			var arr:Array;
		
			arr = ContainerUtil.toArray( owSet( ) );		
			
			assertEquals( arr.length, 0 );

		
			arr = ContainerUtil.toArray( owSet( [ "a" ] ) );		
			
			assertEquals( arr.length, 1 );
			assertEquals( arr[0], "a" );
			
		
		
		}



		public function test_getSetUnion( ):void
		{
		
			var set1:IOWSet = owSet( [ "a" ] );
			var set2:IOWSet = owSet( [ "b", "c" ] );
		
			var union:IRSet = ContainerUtil.getSetUnion( owSet( [ set1, set2  ] ) );
			
			
			assertTrue( union.compare( owSet( [ "a", "b", "c" ] ) ).isEqual   );
		
		
		
		}





		
		public function test_testEqualityByWalking( ):void
		{
		
			
			var b1:IRWBag = owBag( [ "a", "b" ] );
			var b2:IRWBag = owBag( [ "a", "b" ] );
		
			assertTrue( ContainerUtil.testEqualityByWalking( b1, b2 ) );

			b1.add( "c", 1 );					
			
			assertFalse( ContainerUtil.testEqualityByWalking( b1, b2 ) );

			b1.remove( "c" );

			assertTrue( ContainerUtil.testEqualityByWalking( b1, b2 ) );



			b1.add( "a", 2 );
			b2.add( "a", 1 );
			b2.add( "a", 1 );
			
			
			assertTrue( ContainerUtil.testEqualityByWalking( b1, b2 ) );
			


		
		}


	}
	
}